// Copyright (c) 2012 Tobias Reimann
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "stdafx.h"
#include "Helper.h"

using namespace std;

Helper::Helper()
{
}

void Helper::StrToUpper(string& s)
{
	ReplaceAll(s, "a", "A");
	ReplaceAll(s, "b", "B");
	ReplaceAll(s, "c", "C");
	ReplaceAll(s, "d", "D");
	ReplaceAll(s, "e", "E");
	ReplaceAll(s, "f", "F");
	ReplaceAll(s, "g", "G");
	ReplaceAll(s, "h", "H");
	ReplaceAll(s, "i", "I");
	ReplaceAll(s, "j", "J");
	ReplaceAll(s, "k", "K");
	ReplaceAll(s, "l", "L");
	ReplaceAll(s, "m", "M");
	ReplaceAll(s, "n", "N");
	ReplaceAll(s, "o", "O");
	ReplaceAll(s, "p", "P");
	ReplaceAll(s, "q", "Q");
	ReplaceAll(s, "r", "R");
	ReplaceAll(s, "s", "S");
	ReplaceAll(s, "t", "T");
	ReplaceAll(s, "u", "U");
	ReplaceAll(s, "v", "V");
	ReplaceAll(s, "w", "W");
	ReplaceAll(s, "x", "X");
	ReplaceAll(s, "y", "Y");
	ReplaceAll(s, "z", "Z");
}

void Helper::ReplaceAll(string& base, string a, string b)
{
	int i;
	while (true)
	{
		i = base.find(a);
		if (i == -1)
		{
			break;
		}
		else
		{
			base.replace(i, a.length(), b);
		}
	}
}

bool Helper::Contains(string list[], string entry, int max)
{
	for(int i = 0; i < max; i++)
	{
		if(list[i] == entry) return true;
	}
	return false;
}

bool Helper::Endswith(string haystick, string needle)
{
	if(haystick.length() >= needle.length())
	{
		if(haystick.find(needle) == haystick.length()-needle.length()) return true;
	}
	return false;
}

bool Helper::MiddlePart(string haystick, string needle)
{
	if(haystick.length() >= needle.length() + 2)
	{
		if(haystick.find(needle) == haystick.length()-(needle.length() +2)) return true;
	}
	return false;
}
